﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyClassLibrary;
using MyDB;

namespace MyProgram
{
    public partial class FrmJBT : FrmBase
    {
        public FrmJBT()
        {
            InitializeComponent();
        }

        MedicareDataClassesDataContext db = new MedicareDataClassesDataContext();

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text == "")
            {
                var q = from f in db.JobTitles
                        select f;

                this.dataGridView1.DataSource = q.ToList();
            }
            else
            {
                var q = from f in db.JobTitles
                        where f.職稱.Contains(this.textBox1.Text)
                        select f;

                this.dataGridView1.DataSource = q.ToList();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FrmJBTAdd fd = new  FrmJBTAdd();
            fd.ShowDialog();

            MedicareDataClassesDataContext dba = new MedicareDataClassesDataContext();
            var q = from f in dba.JobTitles
                    select f;

            this.dataGridView1.DataSource = q.ToList();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FrmJBTAdd fd = new FrmJBTAdd();

            if (this.dataGridView1.DataSource != null)
            {
                fd.Divname = this.dataGridView1.SelectedCells[1].Value.ToString();
                fd.ShowDialog();

                MedicareDataClassesDataContext dba = new MedicareDataClassesDataContext();
                var q = from f in dba.JobTitles
                        select f;

                this.dataGridView1.DataSource = q.ToList();
            }
        }
    }
}